package reverseOnlyLetters;

public class Solution {
    public String reverseOnlyLetters(String s) {
        // 反转字母
        int i = 0,j = s.length()-1;
        char[] chars = s.toCharArray();
        while (i<j) {
            if(!Character.isLetter(s.charAt(i))) {
                i++;
            } else if (!Character.isLetter(s.charAt(j))) {
                j--;
            } else {
                char c = chars[i];
                chars[i] = chars[j];
                chars[j] = c;
                i++;
                j--;
            }
        }
        return new String(chars);
    }
}
